package xyz.thoughtset.viewer.modules.excel.service;

import cn.hutool.core.io.FileUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xyz.thoughtset.viewer.common.core.constants.FolderNameConstant;
import xyz.thoughtset.viewer.common.crud.core.service.BaseServiceImpl;
import xyz.thoughtset.viewer.modules.excel.dao.ExportDataInfoDao;
import xyz.thoughtset.viewer.modules.excel.entity.ExportDataInfo;

import java.io.File;
import java.util.List;

@Service
@Transactional
public class ExportDataInfoServiceImpl extends BaseServiceImpl<ExportDataInfoDao, ExportDataInfo> implements ExportDataInfoService {
    private static final List EMPTY_LIST = List.of();
    @Override
    public List<String> templateFiles() {
        File folder = new File(FolderNameConstant.TEMPLATE);
        if (folder.exists() && folder.isDirectory() && folder.canRead() && folder.canWrite() && folder.listFiles() != null && folder.listFiles().length > 0) {
            return FileUtil.loopFiles(folder).stream()
                    .map(file -> file.getName())
                    .toList();
        }
        return EMPTY_LIST;
    }


}
